package com.project.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.project.bean.SellCarBean;
import com.project.bean.UserBean;
import com.project.service.ISellCarService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

@RestController
@RequestMapping("sellCar")
public class SellCarController {
    @Autowired
    private ISellCarService sellCarService;

    @RequestMapping("findByUserId")
    public List<SellCarBean> findByUserId(HttpServletRequest req) {
        UserBean user = (UserBean)req.getSession().getAttribute("loginUser");
        return sellCarService.findByUserId(user.getId());
    }

    @RequestMapping("add")
    public String add(String productId, HttpServletRequest req) {
        UserBean user = (UserBean)req.getSession().getAttribute("loginUser");
        sellCarService.add(productId, user.getId());
        return "ok";
    }

    @RequestMapping("del")
    public String  del(Integer sellCarId) {
       sellCarService.del(sellCarId);
       return "ok";
    }

    @RequestMapping("update")
    public String updateNum(Integer sellCarId, Integer num) {
       sellCarService.updateNum(sellCarId, num);
       return "ok";
    }

        @RequestMapping("getTotalPrice")
    public Integer getTotalPrice(HttpServletRequest req) {
        UserBean user = (UserBean)req.getSession().getAttribute("loginUser");
        return sellCarService.getTotalPrice(user.getId());
    }
}
